/*
 * @Author: GGbeng
 * @Date: 2021-09-29 09:56:20
 * @LastEditTime: 2021-12-16 09:43:22
 * @Description:
 * @FilePath: /hisapp/utils/router.js
 */
import store from '../store/index.js'

const isLogin = () => {
	let obj = {
		token: false,
		isCheck: false,
	}
	obj.token =
		store.state.token && store.state.sessionKey && store.state.userId
			? true
			: false
	let { userInfo } = store.state
	if (!userInfo.userName || !userInfo.userIdcode) {
		obj.isCheck = false
	} else {
		obj.isCheck = true
	}
	return obj
}

let navArr = [
	'navigateTo',
	'redirectTo',
	'reLaunch',
	'switchTab',
	'preloadPage',
	'navigateBack',
]

let resObj = {}
navArr.forEach(i => {
	resObj[i] = params => {
		if (isLogin().token) {
			if (isLogin().isCheck) {
				uni[i](params)
			} else {
				uni.showModal({
					title: '温馨提示',
					content: '亲，实名认证后方可进行业务办理！',
					success(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '/pages/addUserInfo/index',
							})
						}
					},
				})
			}
		} else {
			store.commit('getUserInfo', params)
		}
	}
})

module.exports = {
	...resObj,
}
